package com.aaa.service.scl.impl;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.dao.scl.QuestionSclDao;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.mht.QuestionMht;
import com.aaa.entity.scl.QuestionScl;
import com.aaa.service.scl.QuestionSclService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 问题表(QuestionScl)表服务实现类
 *
 * @author
 * @since 2022-07-06 11:51:33
 */
@Service("questionSclService")
public class QuestionSclServiceImpl implements QuestionSclService {
    @Resource
    private QuestionSclDao questionSclDao;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @Override
    public Page queryAll(PageSortEntity pageSortEntity, QuestionScl questionScl) {
        //分页
        PageHelper.startPage(pageSortEntity.getPage(), pageSortEntity.getLimit(), pageSortEntity.getOrderString());
        List<QuestionMht> questionMhts = questionSclDao.queryAll(questionScl);
        Page pageResult = (Page) questionMhts;
        return pageResult;
    }

    /**
     * 新增数据
     *
     * @param questionScl 实例对象
     * @return 实例对象
     */
    @InsertAnn
    @Override
    public boolean insert(QuestionScl questionScl) {
        return questionSclDao.insert(questionScl);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean delete(String id) {
        return questionSclDao.delete(id);
    }

    /**
     * 修改数据
     *
     * @param questionScl 实例对象
     * @return 实例对象
     */
    @UpdateAnn
    @Override
    public boolean update(QuestionScl questionScl) {
        return questionSclDao.update(questionScl);
    }


    /**
     * @param “questionFpa
     * @return boolean
     * @create
     * @description: 查询题目名称是否重名
     */
    @Override
    public boolean repetitionName(QuestionScl questionScl) {
        Integer integer = this.questionSclDao.repetitionName(questionScl);
        if (integer == 0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean repetitionID(QuestionScl questionScl) {
        QuestionScl questionScl1 = questionSclDao.repetitionID(questionScl);
        if (ObjectUtil.isNotEmpty(questionScl1)){
            return false;
        }
        return true;
    }
}
